#include "material_solid.h"

#include <iostream>

SolidMaterial::SolidMaterial(Scene *scene) : Material(scene)
{
  std::cout << "Solid Material Created" << std::endl;
}

SolidMaterial::~SolidMaterial()
{
}

void SolidMaterial::loadAttributes(std::istream &inData)
{
  inData >> m_color.r >> m_color.g >> m_color.b;
  inData >> m_kAmbient >> m_kDiffuse >> m_kSpecular >> m_kReflective;
  inData >> m_kTransparent >> m_kIndexOfRefraction;
  inData.ignore();
}

void SolidMaterial::computeColor(Collision c, Color &targetColor)
{
  Color reflectColor,
        diffuseColor,
        specularColor,
        transparentColor,
        localColor;
  localColor = m_getColor(c);

  if (m_kReflective > 0)
  {
    m_castReflectRay(c, reflectColor);
  }
  if (m_kTransparent > 0)
  {
    m_castTransparentRay(c, m_kIndexOfRefraction, transparentColor);
  }

  m_castLightRays(c, diffuseColor, specularColor);
  
  targetColor = localColor;
  targetColor *= m_kAmbient;

  diffuseColor *= localColor;
  diffuseColor *= m_kDiffuse;
  targetColor += diffuseColor;

  specularColor *= m_kSpecular;
  targetColor += specularColor;

  transparentColor *= m_kTransparent;
  targetColor += transparentColor;

  reflectColor *= m_kReflective;
  targetColor += reflectColor;
}


Color SolidMaterial::m_getColor(Collision c)
{
  return m_color;
}
